/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.report;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import database.ReceipingDAO;
import database.ReportDAO;
import database.StaffAuthenticationDAO;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import model.Issue;
import model.Receipt;
import model.Staff;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Report")
public class WCostReportAction extends ActionSupport{
    private String startDate;
    private String endDate;
    private String displayMode;
    private List<Receipt> receips = new ArrayList<Receipt>();
    private List<CostProduct> reports = new ArrayList<CostProduct>();
    public ReceipingDAO dao = new ReceipingDAO();
   // private String title;
    private String date;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }
    
    
    public String getDisplayMode() {
        return displayMode;
    }

    public void setDisplayMode(String displayMode) {
        this.displayMode = displayMode;
    }

    public List<CostProduct> getReports() {
        return reports;
    }

    public void setReports(List<CostProduct> reports) {
        this.reports = reports;
    }

    
    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public List<Receipt> getReceips() {
        return receips;
    }

    public void setReceips(List<Receipt> receips) {
        this.receips = receips;
    }
    
    
    
     @Action(value = "cost-report", results = {
        @Result(name = "success", location = "/manageReport/w_costReport.jsp")
    })
    public String RevenueBetween() throws ParseException{
        
        Map session = ActionContext.getContext().getSession();
        Staff staff = (Staff) session.get("staff");
        //SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        //Date start = dateFormat.parse(startDate);
        //Date end = dateFormat.parse(endDate);
        
        
//        date = startDate+" - "+endDate;
//        title = "Total Revenue by product ";
//        totalAmount = 0;
//        for(Issue item: issues)
//        {
//            totalAmount += item.getOrder().getTotalAmount();
//        }
//        new StaffAuthenticationDAO().addAction("Create Product Revenue Report", staff.getIdStaff());
        
        return SUCCESS;
    }
     
      @Action(value = "get-cost", results = {
        @Result(name = "success", location = "/manageReport/w_displayCostReport.jsp")
    })
    public String GetCostReport () throws ParseException{
        
        Map session = ActionContext.getContext().getSession();
        //Staff staff = (Staff) session.get("staff");
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        Date start = dateFormat.parse(startDate);
        Date end = dateFormat.parse(endDate);
        
        if(displayMode.equals("Display By Supplier"))
        {
            receips = dao.getAllReceipBetweenDate(start, end);
            session.put("receiptreport", 1);
        }
        else 
        {
            reports = new ReportDAO().GetReceipt(start, end);
            session.put("receiptreport", 2);
        }
//        date = startDate+" - "+endDate;
//        title = "Total Revenue by product ";
//        totalAmount = 0;
//        for(Issue item: issues)
//        {
//            totalAmount += item.getOrder().getTotalAmount();
//        }
//        new StaffAuthenticationDAO().addAction("Create Product Revenue Report", staff.getIdStaff());
        
        return SUCCESS;
    }
}
